package com.my.hotel.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.my.hotel.entity.KfType;
import com.my.hotel.entity.Order;
import com.my.hotel.entity.User;
import com.my.hotel.service.KfTypeService;
import com.my.hotel.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @Autowired
    private KfTypeService kfTypeService;

    @RequestMapping("/getOrderList")
    public String getOrderList(Integer pageNo, HttpSession session, Model model){
        if (pageNo==null){
            pageNo=1;
        }
        PageHelper.startPage(pageNo, 5);
        List<Order> list = orderService.getOrderList();
        PageInfo<Order> pageInfo = new PageInfo<Order>(list);
        model.addAttribute("page",pageInfo);
//        User userMsg = (User) session.getAttribute("userMsg");
       
        User userMsg = new User();
        userMsg.setId(1);
        userMsg.setUsername("zhangsan");

        model.addAttribute("userMsg",userMsg);
        KfType kfType = kfTypeService.getKfType(userMsg.getId());
        model.addAttribute("kfType",kfType);
        return "orderPage";
    }
}
